package redis_homework;

import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class Homework {
    JedisCluster jedisCluster = null;

    @Before
    public void init(){
        JedisPoolConfig jpc = new JedisPoolConfig();
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("192.168.80.100", 6379));
        jedisClusterNode.add(new HostAndPort("192.168.80.100", 6380));
        jedisClusterNode.add(new HostAndPort("192.168.80.100", 6381));
        jedisClusterNode.add(new HostAndPort("192.168.80.100", 6382));
        jedisClusterNode.add(new HostAndPort("192.168.80.101", 6379));
        jedisClusterNode.add(new HostAndPort("192.168.80.101", 6380));
        jedisClusterNode.add(new HostAndPort("192.168.80.102", 6379));
        jedisClusterNode.add(new HostAndPort("192.168.80.102", 6380));
        jedisCluster = new JedisCluster(jedisClusterNode, jpc);
    }
    @Test
    public void setTest(){
        jedisCluster.hset("user:1", "name", "zhangsan");
        jedisCluster.expire("user:1", 10);
    }
    @Test
    public void getTest(){
        System.out.println(jedisCluster.hget("user:1", "name"));

    }
}
